Skip to content

fix(claude): report usage limits on retried turns - #10549

Merged
juliusmarminge merged 1 commit into
pingdotgg:mainfrom
StiensWout:t3code/claude-retry-limit-errors
Sep 7, 2026
Merged

fix(claude): report usage limits on retried turns#10549
juliusmarminge merged 1 commit into
pingdotgg:mainfrom
StiensWout:t3code/claude-retry-limit-errors

Conversation

@StiensWout

@StiensWout StiensWout commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

What Changed

Claude turns retried while still limited now report "Claude usage limit reached" instead of "Claude gave up after repeated API errors", even when the CLI sends no new rate_limit_event.

Closes #10544. Alternative to #10546, with assistant-error evidence replaced when a later parent response arrives.

Why

The retry still carries structured assistant.error: "rate_limit". Record whether the latest top-level assistant message reports that error and use the existing result fallback. This fixes every client through the adapter without parsing the CLI's text or changing contracts.

Keep this evidence separate from rejectedRateLimitTypes: the assistant error supplies no window identity, while that set tracks individual windows and their recovery. Replace the assistant flag on each parent response rather than latching it for the entire turn, so a later normal response or different error cannot leave an obsolete usage-limit hint. Subagent messages neither set nor clear the parent flag. Both normal and synthetic turns start with fresh state.

The existing result handling still owns error precedence, including explicit errors, overloads, and interruption.

Verification

  • Claude adapter suite: 126 tests pass, including nine new cases for assistant-only limits, repeated turns, later recovery/errors, subagent isolation, and error precedence. Result fixtures use the report's is_error: true.
  • Running the six new classification/retry cases against the unfixed adapter fails the three expected positive cases.
  • Server typecheck passes, with existing Effect suggestions only. Targeted lint, formatting, and git diff --check pass.

Implemented with GPT-6 in the Codex harness through T3 Code.

Note

Report usage-limit message on retried Claude turns with assistant rate-limit evidence

  • Adds per-turn tracking of assistant rate-limit evidence in ClaudeTurnState so a terminal API failure can be classified as a usage-limit error when the current turn saw a rate-limit response.
  • Resets the assistant-rate-limit flag at the start of each new Claude turn so evidence from a prior turn does not carry over.
  • The result finalizer in makeClaudeAdapter now includes assistant rate-limit state alongside the existing rejected rate-limit event state when building the usage-limit fallback message.
  • Adds parameterized tests covering consecutive usage-limit failures, terminal failures without new rate-limit evidence, and scenarios where more specific outcomes (overload, tool error, interrupt) take precedence.
  • Risk: the result finalizer in apps/server/src/provider/Layers/ClaudeAdapter.ts changes which message a failed turn reports; turns that previously got a generic repeated-API-error message may now report a usage-limit message when assistant rate-limit evidence is present.

Macroscope summarized af3a725.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Claude error messaging when assistant responses indicate rate limits.
    • Correctly distinguishes usage-limit messages from generic API errors across parent and subagent responses.
    • Prevented rate-limit details from incorrectly carrying over into later turns.
    • Improved handling of repeated rate limits and related terminal failures.

@github-actions github-actions Bot added size:XS 0-9 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Sep 7, 2026
@macroscopeapp

macroscopeapp Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at af3a725

Macroscope's review found this PR approvable — This is a focused Claude adapter bug fix that reports usage-limit failures correctly on retried turns while preserving existing error precedence and resetting evidence between turns. The production change is localized, has targeted test coverage, and introduces no schema, configuration, deployment, or sensitive-data impact.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 2b3f7391-fddc-4be1-ba9d-a1022da1b03c

📥 Commits

Reviewing files that changed from the base of the PR and between 1d1bf50 and af3a725.

📒 Files selected for processing (2)
  • apps/server/src/provider/Layers/ClaudeAdapter.test.ts
  • apps/server/src/provider/Layers/ClaudeAdapter.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The Claude adapter now records assistant rate-limit errors and uses them to classify terminal API failures. Tests cover single-turn, repeated-turn, subagent, overload, tool-error, and interrupt cases.

Changes

Claude rate-limit classification

Layer / File(s) Summary
Track assistant rate-limit state
apps/server/src/provider/Layers/ClaudeAdapter.ts
ClaudeTurnState stores whether the latest assistant message has error === "rate_limit". The state initializes for synthetic and regular turns and updates when assistant messages arrive.
Classify terminal failures
apps/server/src/provider/Layers/ClaudeAdapter.ts, apps/server/src/provider/Layers/ClaudeAdapter.test.ts
Terminal results use assistant rate-limit state when selecting the Claude usage-limit message. Tests cover repeated turns, subagent responses, terminal errors, interrupts, and emitted assistant-rate-limit evidence.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to af3a7

Claude retries that retain a usage-limit error now report the usage-limit message rather than a generic repeated API failure, while normal recovery and higher-priority terminal errors retain their existing behavior. No current merge-blocking risk remains.

Suggested reviewers: juliusmarminge, t3dotgg

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the fix for usage-limit reporting on retried Claude turns.
Description check ✅ Passed The description explains what changed, why it changed, verification results, and scope. The repository checklist section is omitted, but the description is otherwise complete and focused.
Linked Issues check ✅ Passed The implementation directly addresses issue [#10544] by tracking assistant rate-limit evidence across retries, refreshing it per parent response, isolating subagent messages, and preserving error prec…
Out of Scope Changes check ✅ Passed The changes are limited to Claude adapter state handling and related tests. They directly support the linked issue and stated objectives, with no unrelated code changes identified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@juliusmarminge
juliusmarminge merged commit 3bf74eb into pingdotgg:main Sep 7, 2026
22 checks passed
github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Sep 8, 2026
## What's Changed
* fix(mobile): keep pending messages in the chat timeline by @juliusmarminge in pingdotgg/t3code#10449
* fix(mobile): show connection status in the floating pill instead of a second one by @juliusmarminge in pingdotgg/t3code#10440
* fix: use Pierre icons consistently for attachments by @juliusmarminge in pingdotgg/t3code#10475
* feat(mobile): open the thread screen as soon as a new task is submitted by @juliusmarminge in pingdotgg/t3code#10435
* fix(devcontainer): make repository setup work by @saphid in pingdotgg/t3code#7875
* fix(projects): prevent invalid script IDs from crashing threads by @saphid in pingdotgg/t3code#10019
* fix(mobile): hide changed-files navigator and restore refresh in raw diff fallback by @lnieuwenhuis in pingdotgg/t3code#9828
* fix(ios): scroll short source files from blank space by @juliusmarminge in pingdotgg/t3code#10178
* feat(mobile): start a new thread on an existing branch by @StiensWout in pingdotgg/t3code#10359
* fix(mobile): improve font-size slider performance and prevent maximum update depth errors by @bbernag in pingdotgg/t3code#7138
* fix(web): keep composer toolbar controls anchored during transitions by @juliusmarminge in pingdotgg/t3code#10478
* fix(web): resize the floating preview from any edge by @juliusmarminge in pingdotgg/t3code#10467
* fix(mobile): prevent chat from disappearing when scrolling by @juliusmarminge in pingdotgg/t3code#10479
* fix(mobile): smooth composer status pill resizing by @juliusmarminge in pingdotgg/t3code#10484
* fix(mobile): release initial scroll target after dragging by @juliusmarminge in pingdotgg/t3code#10483
* fix(mobile): animate thread lifecycle transitions consistently by @juliusmarminge in pingdotgg/t3code#10487
* fix(mobile): restore assistant message bottom padding by @juliusmarminge in pingdotgg/t3code#10491
* fix(mobile): preserve chat rows when toggling commands by @juliusmarminge in pingdotgg/t3code#10492
* feat(web): group onboarding project import by repository by @t3dotgg in pingdotgg/t3code#10493
* fix(web): remove inserted citations on cancel by @extoci in pingdotgg/t3code#10518
* fix(mobile): match Working status color to desktop by @baptisteArno in pingdotgg/t3code#10515
* fix(mobile): wait for native thread scroll before reveal by @juliusmarminge in pingdotgg/t3code#10486
* fix(web): tolerate servers that predate git identity in project import by @juliusmarminge in pingdotgg/t3code#10547
* fix(web): restore settled PR colors on hover by @flamboh in pingdotgg/t3code#10023
* fix(web): keep popup triggers steady when pressed by @dominic-r in pingdotgg/t3code#10468
* fix(web): keep project favicon shape consistent across sizes by @sameerr03 in pingdotgg/t3code#10502
* fix(claude): report usage limits on retried turns by @StiensWout in pingdotgg/t3code#10549
* refactor(desktop): classify backend exports by @juliusmarminge in pingdotgg/t3code#10265
* refactor(desktop): classify electron exports by @juliusmarminge in pingdotgg/t3code#10266
* refactor(desktop): classify app exports by @juliusmarminge in pingdotgg/t3code#10267
* refactor(desktop): classify preview exports by @juliusmarminge in pingdotgg/t3code#10268
* ci(knip): enforce desktop exports by @juliusmarminge in pingdotgg/t3code#10269
* fix(web): remove excess sidebar thread spacing by @maria-rcks in pingdotgg/t3code#10569
* fix(web): make settings project scopes searchable and scrollable by @maria-rcks in pingdotgg/t3code#10570
* fix(web): use `tabular-nums` with the ui font for sidebar timer by @extoci in pingdotgg/t3code#10592
* fix(web): correct pending question attachment message by @dominic-r in pingdotgg/t3code#10599
* fix(mobile): restore brand artwork in the Android adaptive icon by @juliusmarminge in pingdotgg/t3code#10598
* fix(mobile): configure iOS Keychain access group by @VedankPurohit in pingdotgg/t3code#3665
* fix(web): remember Composer Fast mode across new chats by @aravhawk in pingdotgg/t3code#2981
* fix(server): disable executable capabilities in Claude metadata generation by @maxwellyoung in pingdotgg/t3code#4169
* Add stop thread keybinding command by @jakeleventhal in pingdotgg/t3code#4308

## New Contributors
* @bbernag made their first contribution in pingdotgg/t3code#7138
* @baptisteArno made their first contribution in pingdotgg/t3code#10515
* @aravhawk made their first contribution in pingdotgg/t3code#2981

**Full Changelog**: pingdotgg/t3code@v0.0.39...v0.0.40

Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.0.40
github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Sep 8, 2026
## What's Changed
* fix(mobile): wait for native thread scroll before reveal by @juliusmarminge in pingdotgg/t3code#10486
* fix(web): tolerate servers that predate git identity in project import by @juliusmarminge in pingdotgg/t3code#10547
* fix(web): restore settled PR colors on hover by @flamboh in pingdotgg/t3code#10023
* fix(web): keep popup triggers steady when pressed by @dominic-r in pingdotgg/t3code#10468
* fix(web): keep project favicon shape consistent across sizes by @sameerr03 in pingdotgg/t3code#10502
* fix(claude): report usage limits on retried turns by @StiensWout in pingdotgg/t3code#10549
* refactor(desktop): classify backend exports by @juliusmarminge in pingdotgg/t3code#10265
* refactor(desktop): classify electron exports by @juliusmarminge in pingdotgg/t3code#10266
* refactor(desktop): classify app exports by @juliusmarminge in pingdotgg/t3code#10267
* refactor(desktop): classify preview exports by @juliusmarminge in pingdotgg/t3code#10268
* ci(knip): enforce desktop exports by @juliusmarminge in pingdotgg/t3code#10269
* fix(web): remove excess sidebar thread spacing by @maria-rcks in pingdotgg/t3code#10569
* fix(web): make settings project scopes searchable and scrollable by @maria-rcks in pingdotgg/t3code#10570
* fix(web): use `tabular-nums` with the ui font for sidebar timer by @extoci in pingdotgg/t3code#10592
* fix(web): correct pending question attachment message by @dominic-r in pingdotgg/t3code#10599
* fix(mobile): restore brand artwork in the Android adaptive icon by @juliusmarminge in pingdotgg/t3code#10598
* fix(mobile): configure iOS Keychain access group by @VedankPurohit in pingdotgg/t3code#3665
* fix(web): remember Composer Fast mode across new chats by @aravhawk in pingdotgg/t3code#2981
* fix(server): disable executable capabilities in Claude metadata generation by @maxwellyoung in pingdotgg/t3code#4169
* Add stop thread keybinding command by @jakeleventhal in pingdotgg/t3code#4308

## New Contributors
* @aravhawk made their first contribution in pingdotgg/t3code#2981

**Full Changelog**: pingdotgg/t3code@v0.0.40-nightly.20260907.1359...v0.0.40-nightly.20260907.1372

Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.0.40-nightly.20260907.1372
aorwall added a commit to aorwall/t3code that referenced this pull request Sep 8, 2026
Merges `pingdotgg/t3code` `8b2838e0e..a37c664` — 43 commits.

`343` files landed against `343` changed in the upstream range; fork
delta `723` files. Exact match, so nothing upstream changed was dropped.

Details in
[`docs/fork/upstream-merge-log.md`](../blob/merge/upstream-2026-09-08/docs/fork/upstream-merge-log.md).

## Two fork deltas this merge had to re-apply

**Upstream split the server-update banner into two routes.** pingdotgg#10596
added `useAutoBalanceUpdateBanner` beside the single-machine condition
the fork already gates. The conflict was on the first line only, so
resolving it correctly still left the auto-balance route ungated — an
auto-balanced project would have been offered `npx t3` against a backend
that does not implement `server.updateServer`.
`FEATURES.serverUpdateBanner` now carries two gates in `ChatView.tsx`.

**A new settings page needs a gate even though it degrades politely.**
pingdotgg#8103 added `/settings/snap-shot` for desktop window capture. Every
control drives `window.desktopBridge`, and upstream renders an
"unavailable" notice rather than hiding the page, so a hosted build
listed a sidebar section and six searchable rows for a feature it can
never run. Gated with `FEATURES.snapShots`.

Two smaller fixes: `packages/moatless-api` still ran `tsgo --noEmit`
after upstream replaced `@typescript/native-preview` with TypeScript
7.0.2, and `duplicate-adds.mjs` now skips `pnpm-lock.yaml` (it read
`iconv-lite: 0.6.3` as taken twice; `d3-dsv` and `encoding` each declare
it).

## Usable as-is

- Stop-thread keybinding command (pingdotgg#4308).
- Project import tolerates servers that predate the git-identity scan
(pingdotgg#10547).
- Proactive panels open when entering a thread (pingdotgg#10610); pull-request
markdown links open in the panel (pingdotgg#10623); markdown images navigate as
galleries (pingdotgg#10625); pull-request videos play inline (pingdotgg#10617).
- Settings project scopes are searchable and scrollable (pingdotgg#10570); ref
picker stays steady when opening (pingdotgg#9472); sidebar timer uses
`tabular-nums` (pingdotgg#10592); popup triggers stay steady when pressed
(pingdotgg#9468); settled PR colors restore on hover (pingdotgg#10023).
- Composer Fast mode persists across new chats (pingdotgg#2981); inserted
citations are removed on cancel (pingdotgg#10518).
- TypeScript 7.0.2 (pingdotgg#10663) and the knip desktop-export rules (pingdotgg#10269).

## Unsupported in Moatless / needs implementation

- **Cross-platform window capture** (pingdotgg#8103) —
`apps/desktop/src/snapShot/**`,
`apps/web/src/components/settings/SnapShotSettings.tsx`,
`apps/web/src/lib/desktopSnapShot.ts`. Needs an Electron
`window.desktopBridge`; a browser tab has none. Gated behind
`FEATURES.snapShots` in this PR.
- **Auto-balance server update** (pingdotgg#10596) —
`apps/web/src/components/chat/useAutoBalanceUpdateBanner.tsx`. Needs
`server.updateServer`, which Moatless does not dispatch. Gated behind
`FEATURES.serverUpdateBanner` in this PR.
- **Preview recording transfer** (pingdotgg#10572) —
`apps/server/src/mcp/toolkits/preview/handlers.ts`,
`apps/web/src/browser/browserRecordingUpload.ts`. Moves a finished
preview recording into the agent environment over the desktop bridge.
Adds four error types to `packages/contracts/src/previewAutomation.ts`
and no new RPC method, so no union changed. Sits behind the
`previewAutomation.connect` / `focusHost` / `respond` gap already in the
register.
- **Local media linked from remote threads** (pingdotgg#10619) and **browser
editing shortcuts** (pingdotgg#10621) — Electron shell only.
- **iOS Keychain access group** (pingdotgg#3665) and the mobile provider account
badge (pingdotgg#9899) — the fork ships no mobile build against Moatless.

## Backend behavior to consider reproducing in Moatless

- **Name the usage limit and its reset instead of relaying "out of
credits"** (pingdotgg#10473, `apps/server/src/provider/**` Codex adapter).
Moatless owns its provider runtime, so the clearer limit message has to
be produced there.
- **Report usage limits on retried turns** (pingdotgg#10549, Claude adapter). A
retry currently loses the limit signal; same ownership.
- **Disable executable capabilities in Claude metadata generation**
(pingdotgg#4169, `apps/server/src/textGeneration/ClaudeTextGeneration.ts`). Title
and metadata generation should not be able to run tools. Worth mirroring
wherever Moatless generates thread titles.

## Verification

`verify.mjs`: duplicate-adds, tripwires, resolution-check,
unsupported-methods (0 ADD, 0 DROP, 2 KEEP), fmt, lint and typecheck all
pass.

Tests pass except `@t3tools/desktop`, which cannot compile
`scripts/browser-secret-native.test.mjs` because the sandbox has no
`libsecret-1` — 1283 tests pass, 0 fail, and the file is byte-identical
to upstream. New entry in `docs/fork/gaps.md`. `t3` failed
`GrokAdapter.test.ts` once under parallel load and passes 42/42 alone.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---
Moatless task:
https://moatless.soaplabstest.com/tasks/6d8ea486-2fcb-4c25-bd34-dcd15cc4a7ac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Retrying a Claude turn while still limited reports "gave up after repeated API errors" again

2 participants